import javax.servlet.ServletConfig;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/configservlet",initParams = {@WebInitParam(name = "encoding",value = "UTF-8")})
public class ConfigServlet extends HttpServlet {
    @Override
    protected  void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = resp.getWriter();
        ServletConfig config =this.getServletConfig();
        String param = config.getInitParameter("encoding");

        pw.println("参数encoding的值为：" + param);
    }
}